package ink.ykb.demo.permission.dao;
import java.util.List;

import org.beetl.sql.core.annotatoin.Sql;
import org.beetl.sql.core.mapper.BaseMapper;

import ink.ykb.demo.permission.entity.UserRole;

public interface UserRoleDao extends BaseMapper<UserRole> {

  
  
  /**
   * 根据用户ID和角色ID获取关联角色配置
   * @param userId
   * @param roleId
   * @return
   */
  @Sql("select * from user_role where user_id = ? and role_id = ?")
  UserRole getUserRole(Long userId, Long roleId);
  
  /**
   * 根据用户ID和角色ID获取关联角色配置(加锁)
   * @param userId
   * @param roleId
   * @return
   */
  @Sql("select * from user_role where user_id = ? and role_id = ? for update")
  UserRole getUserRoleAndLock(Long userId, Long roleId);
  
  /**
   * 根据主键查询关联角色配置
   * @param id
   * @return
   */
  @Sql("select * from user_role where id = ?")
  UserRole getUserRole(Long id);
  
  /**
   * 查询用户的所有角色配置
   * @param userId
   * @return
   */
  @Sql("select * from user_role where user_id = ?")
  List<UserRole> getUserRoleByUserId(Long userId);
  
  /**
   * 查询角色对应的所有角色配置
   * @param roleId
   * @return
   */
  @Sql("select * from user_role where role_id = ?")
  List<UserRole> getUserRoleByRoleId(Long roleId);
  
}